Skip to content

feat: add a remove button element for semantic#900

Merged
zombieJ merged 8 commits intoreact-component:masterfrom
coding-ice:feat/semantic
Mar 11, 2026
Merged

feat: add a remove button element for semantic#900
zombieJ merged 8 commits intoreact-component:masterfrom
coding-ice:feat/semantic

Conversation

@coding-ice
Copy link
Contributor

@coding-ice coding-ice commented Sep 24, 2025

Summary by CodeRabbit

  • 新功能

    • 支持按语义键(如 item 与 remove)为标签项与关闭按钮分别配置 styles 与 classNames,便于更细粒度样式定制,覆盖标签列表、操作菜单与溢出项。
  • 破坏性变更

    • 组件接口不再使用单一 style 与 className,需迁移到基于语义键的 styles 与 classNames(新增 remove 语义键)。
  • 测试

    • 新增用例验证可编辑标签的关闭按钮在直接渲染与溢出菜单中均接受自定义类名与样式。

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c0de1683-068a-4c67-87f4-e0ee36e58228

📥 Commits

Reviewing files that changed from the base of the PR and between 77c6040 and c4a0326.

📒 Files selected for processing (1)
  • src/TabNavList/TabNode.tsx

Walkthrough

将 Tab 组件的样式/类名 API 从单一的 style/className 重构为按语义键的 styles/classNames 映射,新增语义键 remove;更新 TabNavListTabNodeOperationNode 的 props 与调用,并新增测试覆盖移除按钮的类名与样式。

Changes

Cohort / File(s) Summary
样式 API 语义化重构(TabNode)
src/TabNavList/TabNode.tsx
style?: React.CSSPropertiesclassName?: string 替换为按语义的 styles?: Pick<Partial<Record<SemanticName, React.CSSProperties>>, 'item' | 'remove'>classNames?: Pick<Partial<Record<SemanticName, string>>, 'item' | 'remove'>;组件内部使用 styles?.item/classNames?.item 与移除按钮的 styles?.remove/classNames?.remove
样式传递更新(TabNavList 渲染逻辑)
src/TabNavList/index.tsx
渲染 TabNode 时改为传入按语义的 classNamesstyles 映射(包含 itemremove),并在首个 tab/可编辑场景下合并对应语义样式与类名。
类型扩展(SemanticName 增加 remove)
src/Tabs.tsx
扩展导出类型 SemanticName,新增 'remove' 以支持对移除按钮的按语义 className/style 映射。
下拉操作节点样式支持(OperationNode)
src/TabNavList/OperationNode.tsx
OperationNode 添加 stylesclassNames(至少包含 remove)并在下拉菜单的移除项上应用 classNames?.removestyles?.remove
测试(移除按钮样式/类名)
tests/index.test.tsx, tests/overflow.test.tsx
新增/扩展测试,断言可编辑 Tabs 的移除按钮(标签内与溢出下拉项)可接收并应用自定义 classNames.removestyles.remove(类名与内联样式断言)。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as 应用
  participant Tabs as Tabs
  participant Nav as TabNavList
  participant Node as TabNode
  participant Op as OperationNode

  App->>Tabs: 提供 props (classNames, styles, editable, ...)
  Tabs->>Nav: 转发 tabs 列表与语义化 classNames/styles
  Note over Tabs,Nav: 语义键包含 item / remove / ...
  loop 每个 tab
    Nav->>Node: render(tab, { classNames: {item, remove}, styles: {item, remove}, ... })
    Node->>Node: 使用 classNames?.item / styles?.item 构建项 DOM
    alt 可编辑且显示移除
      Node->>Node: 使用 classNames?.remove / styles?.remove 渲染移除按钮
    end
  end
  Nav->>Op: 溢出菜单渲染时传入 classNames?.remove / styles?.remove
  Op->>Op: 下拉项应用 remove 语义的类与样式
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

我在代码地里轻轻跳,🐰
把 style 分成语义的篮子放,
item 穿好衣裳,remove 戴小帽,
classNames 与 styles 一同跑,
关闭按钮也能闪亮登场。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题'feat: add a remove button element for semantic'准确概括了主要变化:为Tabs组件添加语义化的remove按钮元素支持。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link

vercel bot commented Sep 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
tabs Ready Ready Preview Comment Sep 30, 2025 2:04am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @coding-ice, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the customization capabilities for tab components by introducing a dedicated semantic name for the close button. It refactors the styling and class name props within the TabNode component to accept structured objects, allowing developers to apply distinct styles and classes to both the tab item and its close button. This change provides greater flexibility and control over the visual presentation of tabs.

Highlights

  • New 'close' Semantic Name: A new semantic name, 'close', has been introduced to the SemanticName type, allowing for more granular styling and class management of tab close buttons.
  • Refactored TabNode Styling Props: The TabNode component's style and className props have been replaced with styles and classNames objects. These new props now accept item and close keys, enabling distinct styling for the tab item itself and its close button.
  • Updated TabNavList Prop Passing: The TabNavList component has been updated to pass the new structured styles and classNames objects down to the TabNode component, ensuring the new styling mechanism is utilized.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the ability to style the close button on tabs by introducing a 'close' semantic name. The implementation is well-done and consistent. My main feedback is the lack of updated tests. The new functionality for classNames.close and styles.close should be covered by unit tests to prevent future regressions. I've also left one minor suggestion to improve type consistency.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/TabNavList/index.tsx (1)

438-447: 按语义传递 item/close 的类名与样式 — LGTM;可微调合并以更健壮

在严格类型设置下(如 exactOptionalPropertyTypes),展开 styles?.item 可能触发类型告警。可使用空对象兜底,提升健壮性(行为不变)。

-          item: i === 0 ? styles?.item : { ...tabNodeStyle, ...styles?.item },
+          item: i === 0 ? styles?.item : { ...tabNodeStyle, ...(styles?.item || {}) },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c5dbbb and 8c4f5fd.

📒 Files selected for processing (3)
  • src/TabNavList/TabNode.tsx (5 hunks)
  • src/TabNavList/index.tsx (1 hunks)
  • src/Tabs.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/TabNavList/TabNode.tsx (1)
src/Tabs.tsx (1)
  • SemanticName (37-37)
🔇 Additional comments (7)
src/Tabs.tsx (1)

37-37: 扩展 SemanticName 包含 'close' — LGTM

与下游 TabNode/TabNavList 改动一致。

src/TabNavList/TabNode.tsx (3)

87-94: 为 item 节点应用语义化类名与样式 — LGTM

tabNodeClassNames?.itemstyles?.item 的解构与落点正确。


134-136: 为 close 按钮应用语义化类名与样式 — LGTM

tabNodeClassNames?.closestyles?.close 使用恰当。


5-5: 改为相对导入或确认 '@' 路径别名已配置

仓库搜索仅在 src/TabNavList/TabNode.tsx:5 发现 '@/Tabs' 引用,未找到 tsconfig 的 paths 或其它别名声明;建议改为相对导入以保持一致性:

-import type { SemanticName } from '@/Tabs';
+import type { SemanticName } from '../Tabs';

若需保留 '@' 别名,确认在 tsconfig.json 或构建配置(vite/webpack)中添加 "@/": ["src/"] 并确保构建/类型检查能解析该别名。

src/TabNavList/index.tsx (3)

593-595: header 语义的 className/style 透传 — LGTM

顺序为用户 style 覆盖语义 header,优先级合理。


633-637: indicator 语义的 className/style 透传 — LGTM

indicatorStyle 与自定义样式合并顺序合理。


650-651: 确认:OperationNode 已声明并使用 popupStyle,可直接传入

src/TabNavList/OperationNode.tsx 声明了 popupStyle?: React.CSSProperties(约第29行),并在下拉中以 overlayStyle={popupStyle} 使用(约第198行),因此在 src/TabNavList/index.tsx 传入 popupStyle={styles?.popup} 是安全的。

@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.98%. Comparing base (5a33ccf) to head (c4a0326).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #900      +/-   ##
==========================================
- Coverage   98.98%   98.98%   -0.01%     
==========================================
  Files          18       18              
  Lines         789      788       -1     
  Branches      237      228       -9     
==========================================
- Hits          781      780       -1     
  Misses          8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@li-jia-nan
Copy link
Member

close 按钮有两个,好像漏了一个地方

@coding-ice coding-ice changed the title feat: add 'close' semantic name and update TabNode styles and classNames feat: add a close button element for semantic Oct 9, 2025
@coding-ice
Copy link
Contributor Author

close 按钮有两个,好像漏了一个地方

弹出层的确实漏下了,我补一下~

@li-jia-nan
Copy link
Member

close 按钮有两个,好像漏了一个地方

弹出层的确实漏下了,我补一下~

我不确定这两个地方的 close 是不是要用同一个语义,可以问问 @zombieJ

@vercel
Copy link

vercel bot commented Oct 9, 2025

@coding-ice is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/index.test.tsx (1)

779-807: 简化测试设置以提高清晰度。

测试逻辑正确,但设置可能过于复杂。使用窄容器(100px)和 10 个标签项通常会触发溢出行为,但此测试仅检查可见标签的关闭按钮(.rc-tabs-tab-remove),而不是溢出下拉菜单中的按钮。

建议简化测试设置,使用较少的标签项和正常容器宽度,因为此测试的重点是可见标签的关闭按钮样式,而不是溢出行为。

可以考虑应用以下简化:

  it('support classnames and styles for editable close button', () => {
    const customClassNames = {
      close: 'custom-close',
    };
    const customStyles = {
      close: { background: 'red' },
    };

    const { container } = render(
-      <div style={{ width: 100 }}>
-        <Tabs
-          editable={{
-            onEdit: () => {},
-          }}
-          tabPosition="left"
-          items={Array.from({ length: 10 }).map((_, index) => ({
-            key: `test-${index}`,
-            label: `test-${index}`,
-            icon: 'test',
-          }))}
-          styles={customStyles}
-          classNames={customClassNames}
-        />
-      </div>,
+      <Tabs
+        editable={{
+          onEdit: () => {},
+        }}
+        items={[
+          { key: 'test-1', label: 'test-1', icon: 'test' },
+          { key: 'test-2', label: 'test-2', icon: 'test' },
+        ]}
+        styles={customStyles}
+        classNames={customClassNames}
+      />,
    );

    expect(container.querySelector('.rc-tabs-tab-remove')).toHaveClass('custom-close');
    expect(container.querySelector('.rc-tabs-tab-remove')).toHaveStyle({ background: 'red' });
  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e64d138 and 1b20c6f.

📒 Files selected for processing (2)
  • tests/index.test.tsx (1 hunks)
  • tests/overflow.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/overflow.test.tsx (1)
tests/common/util.tsx (2)
  • getTabs (113-147)
  • triggerResize (149-156)
🔇 Additional comments (1)
tests/overflow.test.tsx (1)

531-556: 测试实现正确,补充了溢出下拉菜单的关闭按钮样式测试。

此测试正确地验证了溢出下拉菜单中关闭按钮的自定义样式和类名应用。测试流程清晰:

  1. 设置可编辑标签和自定义样式
  2. 触发溢出行为
  3. 打开下拉菜单
  4. 验证下拉菜单中的关闭按钮应用了自定义样式

这正是 PR 评论中提到的"弹出层"部分,与 tests/index.test.tsx 中的测试互补,共同覆盖了两种场景下的关闭按钮样式。

基于 PR 评论。

aria-label={removeAriaLabel || 'remove'}
tabIndex={0}
className={`${dropdownPrefix}-menu-item-remove`}
className={clsx(`${dropdownPrefix}-menu-item-remove`, classNames?.close)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 close 语义,不太确定是不是要改为 popup.close

@coding-ice coding-ice changed the title feat: add a close button element for semantic feat: add a remove button element for semantic Oct 13, 2025
@zombieJ zombieJ merged commit f64f80a into react-component:master Mar 11, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants